package net.optix.ip.commands
{
	import com.adobe.cairngorm.business.Responder;
	import com.adobe.cairngorm.commands.Command;
	import com.adobe.cairngorm.control.CairngormEvent;
	
	import mx.collections.ArrayCollection;
	
	import net.optix.ip.business.*;
	import net.optix.ip.events.GetFirmsWorkEvent;
	import net.optix.ip.model.ModelLocator;
	import net.optix.ip.vo.FirmVO;
	

	public class GetFirmsWorkCommand implements Command, Responder
	{
		// attributes ============================
		private var model : ModelLocator = ModelLocator.getInstance();


		// functions ============================
		public function execute( event:CairngormEvent ) : void
		{
			var myEvent:GetFirmsWorkEvent	=	GetFirmsWorkEvent(event);
			var delegate:UserDelegate	=	new UserDelegate();
			delegate.getFirmsWork(this,myEvent.clientID);
		}
		
		//----------------------------------------------------------------------------
		public function onResult( event : * = null ) : void
		{	//trace(event.result);
			try
			{
				var result:XML		=	event.result;
				var firms:ArrayCollection	=	new ArrayCollection();
				for(var i:int=0; i<result.Data.length(); i++)
				{
					firms.addItem(FirmVO.purseFirm(result.Data[i]));
				}
				model.firms	=	firms;
			}
			catch(error:Error)
			{
				
			}
		}
		
		//----------------------------------------------------------------------------
		public function onFault( event : * = null ) : void
		{
			trace(event.fault);
		}

	}
}